#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{int d,v,a;}a[100009];
int n,m,l,s,b[100009];
bool ok[100009];
vector<int> v;
void work(){
    for(int i=1;i<=n;i++){
        if(a[i].a==0){
            int x=(*lower_bound(b+1,b+m+1,a[i].d));
            if(x>=a[i].d&&x<=l&&a[i].v>s)ok[i]=1;
            continue;
        }
        int dis=(s*s-a[i].v*a[i].v)/2/a[i].a;
        dis+=a[i].d;
        if(a[i].a<0){
            int x=(*lower_bound(b+1,b+m+1,a[i].d));
            if(x>=a[i].d&&x<=dis)ok[i]=1;
        }
        else {
            int x=(*upper_bound(b+1,b+m+1,dis));
            if(x>dis&&x<=l)ok[i]=1;
        }
    }
}
bool check(){
    for(int i=1;i<=n;i++){
        if(a[i].a==0){
            int x=-1;
            if((lower_bound(v.begin(),v.end(),a[i].d))!=v.end())x=(*lower_bound(v.begin(),v.end(),a[i].d));
            if(x>=a[i].d&&x<=l&&a[i].v>s){
                if(ok[i]==0){
                    return 0;
                }
            }
            else {
                if(ok[i]==1){
                    return 0;
                }
            }
            continue;
        }

        int dis=(s*s-a[i].v*a[i].v)/2/a[i].a,m=(s*s-a[i].v*a[i].v)%(2*a[i].a);
        dis+=a[i].d;
        if(a[i].a<0){
            int x=-1;
            if((lower_bound(v.begin(),v.end(),a[i].d))!=v.end())x=(*lower_bound(v.begin(),v.end(),a[i].d));
            if(x>=a[i].d&&x<=dis){
                if(ok[i]==0){
                    return 0;
                }
            }
            else {
                if(ok[i]==1){
                    return 0;
                }
            }
        }
        else {
            int x=-1;
            if((upper_bound(v.begin(),v.end(),dis-(m==0)))!=v.end())x=(*upper_bound(v.begin(),v.end(),dis-(m==0)));
            if(x>(dis-(m==0))&&x<=l){
                if(ok[i]==0){
                    return 0;
                }
            }
            else {
                if(ok[i]==1){
                    return 0;
                }
            }
        }
    }
    return 1;
}
void solve(){
    cin>>n>>m>>l>>s;bool f=1;
    for(int i=1;i<=n;i++){
        cin>>a[i].d>>a[i].v>>a[i].a;
        if(a[i].a!=0)f=0;
        ok[i]=0;
    }
    for(int i=1;i<=m;i++)cin>>b[i];b[0]=b[m+1]=-1;
    if(f){
        int cnt=0;
        for(int i=1;i<=n;i++){
            int x=(*lower_bound(b+1,b+m+1,a[i].d));
            if(x>=a[i].d&&x<=l&&a[i].v>s)cnt++;
        }
        cout<<cnt<<" ";
        cout<<m-(cnt!=0)<<"\n";
        return;
    }
    work();
    int ans1=0,ans2=0;
    for(int i=1;i<=n;i++)if(ok[i])ans1++;
    for(int i=0;i<(1<<m);i++){
        v.clear();
        int j=i,id=0;
        while(j){
            id++;
            if(j&1)v.push_back(b[id]);
            j>>=1;
        }
        if(check())ans2=max(ans2,m-__builtin_popcount(i));
    }
    cout<<ans1<<" "<<ans2<<"\n";
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--)solve();
}
